package cn.edu.scau.dao;

import cn.edu.scau.entity.Medicationrecord;
import org.apache.ibatis.jdbc.SQL;

public class MedicationrecordSqlProvider {

    public String insertSelective(Medicationrecord record) {
        SQL sql = new SQL();
        sql.INSERT_INTO("medicationrecord");
        
        if (record.getMedicationrecordid() != null) {
            sql.VALUES("medicationRecordID", "#{medicationrecordid,jdbcType=INTEGER}");
        }
        
        if (record.getCustomerid() != null) {
            sql.VALUES("customerID", "#{customerid,jdbcType=INTEGER}");
        }
        
        if (record.getMedicationrecorddrugname() != null) {
            sql.VALUES("medicationRecordDrugName", "#{medicationrecorddrugname,jdbcType=VARCHAR}");
        }
        
        if (record.getMedicationrecorddosage() != null) {
            sql.VALUES("medicationRecordDosage", "#{medicationrecorddosage,jdbcType=VARCHAR}");
        }
        
        if (record.getMedicationrecordmethod() != null) {
            sql.VALUES("medicationRecordMethod", "#{medicationrecordmethod,jdbcType=VARCHAR}");
        }
        
        if (record.getMedicationrecordshipper() != null) {
            sql.VALUES("medicationRecordShipper", "#{medicationrecordshipper,jdbcType=VARCHAR}");
        }
        
        if (record.getMedicationrecorddispenser() != null) {
            sql.VALUES("medicationRecordDispenser", "#{medicationrecorddispenser,jdbcType=VARCHAR}");
        }
        
        return sql.toString();
    }

    public String updateByPrimaryKeySelective(Medicationrecord record) {
        SQL sql = new SQL();
        sql.UPDATE("medicationrecord");
        
        if (record.getCustomerid() != null) {
            sql.SET("customerID = #{customerid,jdbcType=INTEGER}");
        }
        
        if (record.getMedicationrecorddrugname() != null) {
            sql.SET("medicationRecordDrugName = #{medicationrecorddrugname,jdbcType=VARCHAR}");
        }
        
        if (record.getMedicationrecorddosage() != null) {
            sql.SET("medicationRecordDosage = #{medicationrecorddosage,jdbcType=VARCHAR}");
        }
        
        if (record.getMedicationrecordmethod() != null) {
            sql.SET("medicationRecordMethod = #{medicationrecordmethod,jdbcType=VARCHAR}");
        }
        
        if (record.getMedicationrecordshipper() != null) {
            sql.SET("medicationRecordShipper = #{medicationrecordshipper,jdbcType=VARCHAR}");
        }
        
        if (record.getMedicationrecorddispenser() != null) {
            sql.SET("medicationRecordDispenser = #{medicationrecorddispenser,jdbcType=VARCHAR}");
        }
        
        sql.WHERE("medicationRecordID = #{medicationrecordid,jdbcType=INTEGER}");
        
        return sql.toString();
    }
    public String findByMIdCId(Integer medicationRecordID,Integer customerID){
        SQL sql = new SQL();
        sql.SELECT("medicationRecordID, customerName, medicationRecordDrugName, medicationRecordDosage," +
                "medicationRecordMethod, medicationRecordShipper, medicationRecordDispenser");
        sql.FROM("customer c ,medicationrecord m");
        sql.WHERE("c.customerID=m.customerID");
        if(medicationRecordID!=null){
            sql.WHERE(" m.medicationRecordID like concat('%',#{medicationRecordID},'%')");
        }
        if(customerID!=null){
            sql.WHERE(" m.customerID like concat('%',#{customerID},'%')");
        }

        return sql.toString();
    }
}